package com.teamwings.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RoleUtil {

    @Autowired
    private ISysBaseAPI sysBaseAPI;

    /**
     * 查询该用户是不是管理员
     * @return
     */
    public boolean checkIsAdmin(){
        // 获取当前用户
        String userName = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername();
        List<String> rolesByUsername = sysBaseAPI.getRolesByUsername(userName);
        if (rolesByUsername.indexOf("admin") != -1) {
            return true;
        }
        return false;
    };

    /**
     * 查询该用户是不是管理员
     * @param userName 用户账号
     * @return
     */
    public boolean checkIsAdmin(String userName){
        List<String> rolesByUsername = sysBaseAPI.getRolesByUsername(userName);
        if (rolesByUsername.indexOf("admin") != -1) {
            return true;
        }
        return false;
    };


}
